home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Aidan's Class Libraries / Source / Window & Dialog Classes / BaseWindow.cpp next >
Encoding:
Text File  |  1997-07-20  |  17.4 KB  |  658 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "CLBaseWindow.h"
  5. #include "CLApplication.h"
  6. #include "CLMouseHandler.h"
  7. #include "CLGrowLayout.h"
  8. #include <LowMem.h>
  9. #include "CLWindowLayer.h"
  10. #include "CLWindowDrawer.h"
  11.  
  12. //Difference between the border and the content.  Can only be called when the window is open.
  13. void GetWindowDiffRect( WindowRef window, Rect *diffRect )
  14. {
  15.     RgnHandle strucRgn, contRgn;
  16.  
  17.     strucRgn = NewRgn();
  18.     contRgn = NewRgn();
  19.     GetWindowStructureRgn( window, strucRgn );
  20.     GetWindowContentRgn( window, contRgn );
  21.     diffRect->top = (**strucRgn).rgnBBox.top-(**contRgn).rgnBBox.top;
  22.     diffRect->left = (**strucRgn).rgnBBox.left-(**contRgn).rgnBBox.left;
  23.     diffRect->right = (**strucRgn).rgnBBox.right-(**contRgn).rgnBBox.right;
  24.     diffRect->bottom = (**strucRgn).rgnBBox.bottom-(**contRgn).rgnBBox.bottom;
  25.     DisposeRgn( contRgn );
  26.     DisposeRgn( strucRgn );
  27. }
  28.  
  29. //TBaseWindow::RespondResizeSelf()
  30. //    uses:
  31. //        Use this function to adjust the contents of the window after it has been resized
  32. //    in:
  33. //        Rect oldRect:
  34. //            This rectangle is the old size of the window
  35. //        Rect newRect:
  36. //            This rectangle is the new size of the window
  37. //    out:
  38. //        returns SInt8
  39. //            kWindowSuccess: Everything's groovy..
  40. //            kWindowNotInitializedErr: You forgot to call Init(), you dope!
  41. //    side effects:
  42. //        none, but maybe in your derived classes :-D
  43. SInt8 TBaseWindow::RespondResizeSelf( const Rect &oldRect, const Rect &newRect )
  44. {
  45.     if( !mWindow )
  46.         return( kWindowNotInitializedErr );
  47.     mContent->TrySize( newRect );
  48.     TMouseHandler::SGetMouse()->CalcMouseMoveRgn();
  49.     GetDrawFocus();
  50. //    ::InvalRect( &oldRect );
  51.     if( mNeedWindowDrawers.MoveFirst() ) {
  52.         TWindowDrawer *iter;
  53.         do {
  54.             mNeedWindowDrawers.GetData( iter );
  55.             iter->DrawWindow( this );
  56.         } while( mNeedWindowDrawers.MoveNext() );
  57.     }
  58.     mContent->Draw( this );
  59.     ReleaseDrawFocus();
  60. }
  61.  
  62. //TBaseWindow::TBaseWindow
  63. //    uses:
  64. //        The TBaseWindow constructor, initializes the window to an unusable state.  To use the
  65. //        window, call Init()
  66. //    in:
  67. //        SInt16 resID:
  68. //            The resource ID of this window.  Expect this to be replaced by a structure so that
  69. //            I don't have to change the declaration for this function on every platform I use.
  70. //    side effects:
  71. //        The window is initialized to an unusable state.
  72. TBaseWindow::TBaseWindow( SInt16 resID, TWindowLayer *layer, TLayoutLeaf *content ):
  73.     mhWinRes( resID ),
  74.     mContent( content ),
  75.     mWindow( 0l ),
  76.     mOpen( 0 ),
  77.     mActive( 0 ),
  78.     mLayer( layer )
  79. {
  80. }
  81.  
  82.  
  83. //TBaseWindow::~TBaseWindow()
  84. //    uses:
  85. //        The class destructor.  Do not delete a Window directly, rather call KillWindow().
  86. //    side effects:
  87. //        Low level details of killing the window.
  88. TBaseWindow::~TBaseWindow()
  89. {
  90.     if( mLayer )
  91.         mLayer->RemoveWindow( this );
  92.     if( mContent ) {
  93.         mContent->Close();
  94.         delete mContent;
  95.     }
  96.     if( mWindow ) {
  97.         DoHideWindow();
  98.         ::DisposeWindow( mWindow );
  99.     }
  100. }
  101.  
  102. //TBaseWindow::GetDrawSelf()
  103. //    see TDrawSlate::GetDrawSelf()
  104. Boolean TBaseWindow::GetDrawSelf()
  105. {
  106.     if( !IsOpen() )
  107.         return( false );
  108.     ::GetPort( &mhOldPort );
  109.     ::SetPort( mWindow );
  110.     return( true );
  111. }
  112.  
  113. //TBaseWindow::ReleaseDrawSelf()
  114. //    see TDrawSlate::ReleaseDrawSelf()
  115. Boolean TBaseWindow::ReleaseDrawSelf()
  116. {
  117.     ::SetPort( mhOldPort );
  118.     return( true );
  119. }
  120.  
  121. //TBaseWindow::DoMouseDown()
  122. //    uses:
  123. //        Handle a mouseDown inside of our window
  124. //    in:
  125. //        short partCode:
  126. //            What part of the window the event took place in
  127. //        EventRecord theEvent
  128. //            Event data
  129. //    out:
  130. //        returns SInt8:
  131. //            kWindowNotInitializedErr: You didn't call Init()!
  132. //            kWindowInvalidPartCodeErr: The partCode passed in is invalid
  133. //            kWindowSuccess: Everything's groovy.. yeah.
  134. //            Other: Anything returned by one of our inner functions
  135. //    side effects:
  136. //        If the window wasn't in front, now it is.  Other side effects would be determined in
  137. //        subclasses
  138. void TBaseWindow::DoMouseDown( short partCode, const TMouseButtonEvent *theEvent )
  139. {
  140.     if( !(mWindow && mOpen) )
  141.         return;
  142.     if( !IsActive() ) {
  143.         SelectWindow();
  144.         return;    //Make sure our window is active before clicking in it.
  145.     }
  146.     if( theEvent->button )
  147.         switch( partCode ) {
  148.         case inContent:
  149.             DoContentClick( theEvent );
  150.             break;
  151.         case inDrag:
  152.             DoDrag( theEvent );
  153.             break;
  154.         case inGoAway:
  155.             if( TrackGoAway( mWindow, theEvent->where ) )
  156.                 DoClose();
  157.             break;
  158.         case inGrow:
  159.             DoGrow( theEvent );
  160.             break;
  161.         case inZoomIn:
  162.         case inZoomOut:
  163.             if( TrackBox( mWindow, theEvent->where, partCode ) )
  164.                 DoZoom( partCode, theEvent );
  165.             break;
  166.         case inDesk:
  167.             ::SysBeep(0);
  168.             break;
  169.         }
  170.     else if( partCode == inContent )
  171.         DoContentClick( theEvent );
  172. }
  173.  
  174. //SInt8 TBaseWindow::DoContentClick()
  175. //    uses:
  176. //        Handles a mouse event inside of us.
  177. //    in:
  178. //        EventRecord theEvent:
  179. //            event data
  180. //    out:
  181. //        returns SInt8:
  182. //            kWindowNotInitializedErr: You didn't call Init()
  183. //            kWindowSuccess: everythings groovy
  184. //            Other: determined by subclasses
  185. void TBaseWindow::DoContentClick( const TMouseButtonEvent *theEvent )
  186. {
  187. }
  188.  
  189. //TBaseWindow::DoShowWindow()
  190. //    uses:
  191. //        Show this window
  192. //    out:
  193. //        returns SInt8:
  194. //            kWindowNotInitializedErr: You didn't call Init()
  195. //            kWindowSuccess: Everything's groovy..
  196. //    side effects:
  197. //        The window is visible
  198. SInt8 TBaseWindow::DoShowWindow()
  199. {
  200.     Rect stdRect, tempRect;
  201.  
  202.     if( !IsOpen() ) {
  203.         //::ShowWindow( mWindow );
  204.         //This actually shows the window
  205.         mLayer->AddWindow( this );
  206.         stdRect = qd.screenBits.bounds;
  207.         GetWindowDiffRect( mWindow, &tempRect );
  208.         stdRect.top += ::GetMBarHeight()-tempRect.top;
  209.         stdRect.bottom -= tempRect.bottom;
  210.         stdRect.left -= tempRect.left;
  211.         stdRect.right -= tempRect.right;
  212.         ::InsetRect( &stdRect, 3, 3 );
  213.         ::SetWindowStandardState( mWindow, &stdRect );
  214.         mOpen = true;
  215.     }
  216.     return( kWindowSuccess );
  217. }
  218.  
  219. //TBaseWindow::DoHideWindow()
  220. //    uses:
  221. //        Hide this window
  222. //    out:
  223. //        returns SInt8:
  224. //            kWindowNotInitializedErr: You didn't call Init()
  225. //            kWindowSuccess: Everything's groovy..
  226. //    side effects:
  227. //        The window is invisible
  228. SInt8 TBaseWindow::DoHideWindow()
  229. {
  230.     if( !mWindow )
  231.         return( kWindowNotInitializedErr );
  232.     if( mOpen ) {
  233.         mOpen=false;
  234.         mLayer->RemoveWindow( this );
  235.     }
  236.     return( kWindowSuccess );
  237. }
  238.  
  239. //TBaseWindow::DoUpdate()
  240. //    uses:
  241. //        Respond to update events
  242. //    out:
  243. //        returns SInt8:
  244. //            kWindowNotInitializedErr: You didn't call Init()
  245. //            kWindowSuccess: Everything's.. just fine.
  246. //            Other: to be determined by subclasses.
  247. SInt8 TBaseWindow::DoUpdate()
  248. {
  249.     int retVal;
  250.     GrafPtr oldPort;
  251.  
  252.     if( !mWindow )
  253.         return(kWindowNotInitializedErr);
  254.     GetPort( &oldPort );
  255.     BeginUpdate( mWindow );
  256.     Draw();
  257.     EndUpdate( mWindow );
  258.     SetPort( oldPort );
  259.     //if we've been exposed, it could mean that a system window we don't have control over has
  260.     //changed positions, so the mouse moved region must be updated.
  261.     //if( FrontWindow()==this )
  262.         //TMouseHandler::SGetMouse()->CalcMouseMoveRgn();
  263.     return( kWindowSuccess );
  264. }
  265.  
  266. //TBaseWindow::DrawSelf()
  267. //    uses:
  268. //        Where the actual Window drawing takes place.  Override this in your subclasses to
  269. //        display content.
  270. //    side effects:
  271. //        The area inside of the window is erased.
  272. //        Determined by subclasses
  273. void TBaseWindow::DrawSelf()
  274. {
  275.     if( mNeedWindowDrawers.MoveFirst() ) {
  276.         TWindowDrawer *iter;
  277.         do {
  278.             mNeedWindowDrawers.GetData( iter );
  279.             iter->DrawWindow( this );
  280.         } while( mNeedWindowDrawers.MoveNext() );
  281.     }
  282.     mContent->Draw( this );
  283. }
  284.  
  285. void TBaseWindow::AddDrawer( TWindowDrawer *draw ) {
  286.     if( mNeedWindowDrawers.FindIndex( draw )!=-1 )
  287.         return;
  288.     mNeedWindowDrawers.MoveLast();
  289.     mNeedWindowDrawers.AddNext( draw );
  290. }
  291.  
  292. //The area occupied by the GrowIcon and the scroll bars.
  293. void GetGrowRgn( const Rect &windowRect, RgnHandle copyTo ) {
  294.     Rect tempRect;
  295.     RgnHandle tempRgn1, tempRgn2;
  296.  
  297.     OpenRgn();
  298.         tempRect.top = windowRect.bottom-15;
  299.         tempRect.bottom = windowRect.bottom;
  300.         tempRect.left = windowRect.left;
  301.         tempRect.right = windowRect.right;
  302.         FrameRect( &tempRect );
  303.         tempRect.left = windowRect.right-15;
  304.         tempRect.top = windowRect.top;
  305.         tempRect.bottom = windowRect.bottom-15;
  306.         FrameRect( &tempRect );
  307.     CloseRgn( copyTo );
  308. }
  309.  
  310. //TBaseWindow::DoGrow()
  311. //    uses:
  312. //        Used internally by TBaseWindow to handle a click in the grow box.  This function will
  313. //        be moved into a TSizeableLayout (or something like that) which will grow the window
  314. //        and will also be able to handle size negotiations inside a window
  315. //    in:
  316. //        EventRecord &theEvent
  317. //            The event which generated this grow call
  318. //    out:
  319. //        returns SInt8
  320. //            kWindowNotInitializedErr: You didn't call Init()
  321. //            kWindowSuccess: Everything's.. Just fine.
  322. void TBaseWindow::DoGrow( const TMouseButtonEvent *event )
  323. {
  324.     long retval;
  325.     Rect growRect, oldSize, newSize;
  326.  
  327.     if( !mWindow )
  328.         return;
  329.     growRect = mContent->GetLargestSize();
  330.     OffsetRect( &growRect, -growRect.left, -growRect.top );
  331.     growRect.left = 64;
  332.     growRect.top = 64;
  333.     growRect.right++;
  334.     growRect.bottom++;
  335.     retval = GrowWindow( mWindow, event->where, &growRect );
  336.     if( retval )
  337.     {
  338.         oldSize = ::GetWindowPort( mWindow )->portRect;
  339.         ::OffsetRect( &oldSize, -oldSize.left, -oldSize.top );
  340.         ::SizeWindow( mWindow, retval&0x0000ffff, retval>>16, false );
  341.         newSize = ::GetWindowPort( mWindow )->portRect;
  342.         ::OffsetRect( &newSize, -newSize.left, -newSize.top );
  343. //        GetDrawFocus();
  344.         RespondResizeSelf( oldSize, newSize );
  345. //        ReleaseDrawFocus();
  346.     }
  347. }
  348.  
  349. //TBaseWindow::DoDrag()
  350. //    uses:
  351. //        Used internally by TBaseWindow to react to a click in the dragging area of a window
  352. //    in:
  353. //        EventRecord theEvent
  354. //            The event which caused the drag
  355. //    out:
  356. //        returns SInt8
  357. //            kWindowNotInitializedErr:  You didn't call Init()
  358. //            kWindowSuccess: The window has been moved
  359. //    side effects:
  360. //        The window will be at a new position on the screen
  361. void TBaseWindow::DoDrag( const TMouseButtonEvent *theEvent )
  362. {
  363.     Rect dragRect;
  364.     RgnHandle theRgn;
  365.     RGBColor col;
  366.     col.red= 0; col.green= 0; col.blue= 0;
  367.     ::RGBForeColor( &col );
  368.  
  369.     if( !mWindow )
  370.         return;
  371.     dragRect = qd.screenBits.bounds;
  372.     //DragWindow() brings a window to the front.  This doesn't mesh with Floating Windows.
  373.     //if( !TFloatingWindow::sFloatList.MoveFirst() )
  374.     //    DragWindow( mWindow, theEvent->where, &dragRect );
  375.     //else {
  376.         //The strategy we employ here is simple:  Call DragGrayRgn() and MoveWindow() to
  377.         //simulate a call to DragWindow().
  378.         //Get the region
  379.         theRgn= ::NewRgn();
  380.         ::GetWindowStructureRgn( mWindow, theRgn );
  381.         Rect theRect;
  382.         //This is important because MoveWindow moves the content region to the specified coords
  383.         //when we obviously want to move relative to the structure region
  384.         GetWindowDiffRect( mWindow, &theRect );
  385.         GrafPtr oldPort, newPort;
  386.         ::GetPort( &oldPort );
  387.         newPort= TApplication::SCurApp()->GetGlobalPort();
  388.         ::SetPort( newPort );
  389.         //Now we do clipping
  390.         RgnHandle above= ::NewRgn();
  391.         ClipAbove( above );
  392.         ::SetClip( above );
  393.         //Drag the outline
  394.         UInt32 dragRet= ::DragGrayRgn( theRgn, theEvent->where, &dragRect, &dragRect, noConstraint, 0l );
  395.         //We're not going to draw all over the desktop anymore
  396.         ::SetPort( oldPort );
  397.         ::DisposeRgn( above );
  398.         //::DisposeRgn( bigRgn );
  399.         delete newPort;
  400.         //Move the window to the coordinates we got (offset by the diffRect from before)
  401.         if( dragRet!=(0x80008000) )
  402.             ::MoveWindow( mWindow, (**theRgn).rgnBBox.left-theRect.left, (**theRgn).rgnBBox.top-theRect.top, false );
  403.         //Clean up memory
  404.         ::DisposeRgn( theRgn );
  405.         TMouseHandler::SGetMouse()->CalcMouseMoveRgn();
  406.     //}
  407. }
  408.  
  409. void TBaseWindow::DoZoom( short partCode, const TMouseButtonEvent *theEvent )
  410. {
  411.     Rect diffRect, stdState;
  412.     if( partCode == inZoomOut )
  413.     {
  414.         GetWindowDiffRect( mWindow, &diffRect );
  415.         stdState = mContent->GetLargestSize();
  416.         OffsetRect( &stdState, -stdState.left, -stdState.top );
  417.         OffsetRect( &stdState, -diffRect.left, -diffRect.top+GetMBarHeight() );
  418.         if( stdState.right >= qd.screenBits.bounds.right )
  419.             stdState.right = qd.screenBits.bounds.right;
  420.         if( stdState.bottom >= qd.screenBits.bounds.bottom )
  421.             stdState.bottom = qd.screenBits.bounds.bottom;
  422.         stdState.right -= diffRect.right;
  423.         stdState.bottom -= diffRect.bottom;
  424.         SetWindowStandardState( mWindow, &stdState );
  425.     }
  426.     GrafPtr oldPort;
  427.     Rect oldSize, newSize;
  428.  
  429.     if( !mWindow )
  430.         return;
  431.     GetPort( &oldPort );
  432.     SetPort( mWindow );
  433.     oldSize = ::GetWindowPort( mWindow )->portRect;
  434.     /*if( TFloatingWindow::sFloatList.MoveFirst() ) {
  435.         TFloatingWindow *floatWin;
  436.         TFloatingWindow::sFloatList.GetData( floatWin );
  437.         ::SendBehind( mWindow, floatWin->GetWindow() );
  438.         ::HiliteWindow( mWindow, true );
  439.         ZoomWindow( mWindow, partCode, false );
  440.     }
  441.     else*/
  442.         ZoomWindow( mWindow, partCode, false );
  443.     newSize = ::GetWindowPort( mWindow )->portRect;
  444.     SetPort( oldPort );
  445.     RespondResizeSelf( oldSize, newSize );
  446. }
  447.  
  448. SInt8 TBaseWindow::MakeActive( Boolean active ) {
  449.     SInt8 retVal= kWindowSuccess;
  450.     if( !mWindow )
  451.         return( kWindowNotInitializedErr );
  452.     mActive= active;
  453.     ::HiliteWindow( mWindow, active );
  454.     if( mContent )
  455.         retVal= mContent->MakeActive( active );
  456.     //if( active )
  457.         //TMouseHandler::SGetMouse()->CalcMouseMoveRgn();
  458.     return( retVal );
  459. }
  460.  
  461. SInt8 TBaseWindow::DoClose() {
  462.     if( !mWindow )
  463.         return( kWindowNotInitializedErr );
  464.     return( DoHideWindow() );
  465. }
  466.  
  467. SInt8 TBaseWindow::Init() {
  468.     mWindow = ::GetNewCWindow( mhWinRes, 0l, (WindowRef)-1l );
  469.     if( !mWindow )
  470.         return( kWindowNotInitializedErr );
  471.     ::SetWRefCon( mWindow, (unsigned long)this );    //Highly important code.
  472.         //This is the only way we can get the class from the WindowRef.
  473.     mOpen = false;    //Everything starts out invisible.
  474.  
  475.     Rect rect= GetWindowPort( mWindow )->portRect; //Initialize our content
  476.     ::OffsetRect( &rect, -rect.left, -rect.top );
  477.  
  478.     int var= ::GetWVariant( mWindow );
  479.     switch( var ) {
  480.     case documentProc:
  481.     case zoomDocProc:
  482.         mContent= new TGrowLayout( 0, mContent );
  483.         mContent->Init();
  484.         break;
  485.     };
  486.     mContent->AttachedToWindow( this, rect );
  487.     return( kWindowSuccess );
  488. }
  489.  
  490. SInt8 TBaseWindow::SetWTitle( const Str255 theString ) {
  491.     if( !mWindow )
  492.         return( kWindowNotInitializedErr );
  493.     ::SetWTitle( mWindow, theString );
  494.     return( kWindowSuccess );
  495. }
  496.  
  497. SInt8 TBaseWindow::GetWTitle( Str255 theTitle )
  498. {
  499.     if( !mWindow )
  500.         return( kWindowNotInitializedErr );
  501.     ::GetWTitle( mWindow, theTitle );
  502.     return( kWindowSuccess );
  503. }
  504.  
  505. void TBaseWindow::HandleMouse( TMouseButtonEvent *ev )
  506. {
  507.     WindowRef window;
  508.  
  509.     SelectWindow();
  510.     DoMouseDown( FindWindow( ev->where, &window ), ev );
  511. }
  512.  
  513. void TBaseWindow::Draw()
  514. {
  515.     if( GetDrawFocus() ) {
  516.         DrawSelf();
  517.         MarkChanged( GetWindowPort( mWindow )->portRect );
  518.         ReleaseDrawFocus();
  519.     }
  520. }
  521.  
  522. void TBaseWindow::SelectWindow()
  523. {
  524.     WindowRef floatWin;
  525.     UInt32 data;
  526.  
  527.     //if( !TFloatingWindow::sFloatList.MoveFirst() ) {
  528.     /*    ::SelectWindow( mWindow );
  529.         if( shFrontWindow ) {
  530.             shFrontWindow->MakeActive( false );
  531.         }
  532.         shFrontWindow= this;
  533.         MakeActive( true );
  534.         return;*/
  535.     mLayer->SelectWindow( this );
  536.     //}
  537.     /*TFloatingWindow::sFloatList.GetData( floater );
  538.     floatWin= floater->GetWindow();
  539.     ::SendBehind( mWindow, floatWin );
  540.     if( shFrontWindow ) {
  541.         shFrontWindow->MakeActive( false );
  542.     }
  543.     shFrontWindow= this;
  544.     MakeActive( true );*/
  545. }
  546.  
  547. void TBaseWindow::LocalToGlobal( Point *pt )
  548. {
  549.     GrafPtr oldPort;
  550.  
  551.     ::GetPort( &oldPort );
  552.     ::SetPort( mWindow );
  553.     ::LocalToGlobal( pt );
  554.     ::SetPort( oldPort );
  555. }
  556.  
  557. void TBaseWindow::GlobalToLocal( Point *pt )
  558. {
  559.     GWorldPtr globWorld, world;
  560.     GDHandle globDev, dev;
  561.     TApplication::SCurApp()->GetGlobalWorld( globWorld, globDev );
  562.     ::GetGWorld( &world, &dev );
  563.     ::SetGWorld( globWorld, globDev );
  564.     GrafPtr( oldPort );
  565.     ::GetPort( &oldPort );
  566.     ::SetPort( mWindow );
  567.     ::GlobalToLocal( pt );
  568.     ::SetPort( oldPort );
  569.     ::SetGWorld( world, dev );
  570. }
  571.  
  572. void TBaseWindow::ClipAbove( RgnHandle ret )
  573. {
  574.     if( !ret )
  575.         return;
  576.     GWorldPtr globWorld, world;
  577.     GDHandle globDev, dev;
  578.     GrafPtr globPort, port;
  579.     ::GetGWorld( &world, &dev );
  580.     TApplication::SCurApp()->GetGlobalWorld( globWorld, globDev );
  581.     ::SetGWorld( globWorld, globDev );
  582.     ::GetPort( &port );
  583.     ::SetPort( TApplication::SCurApp()->GetGlobalPort() );
  584.     RgnHandle oldClip= ::NewRgn();
  585.     ::GetClip( oldClip );
  586.     Rect bigRect;
  587.     RgnHandle temp= ::NewRgn();
  588.     ::SetRect( &bigRect, -32767, -32767, 32767, 32767 );
  589.     ::RectRgn( temp, &bigRect );
  590.     ::SetClip( temp );
  591.     WindowRecord *win= (WindowRecord*)mWindow;
  592.     ::ClipAbove( mWindow );
  593.     ::GetClip( ret );
  594.     ::SetClip( oldClip );
  595.     ::DisposeRgn( oldClip );
  596.     ::DisposeRgn( temp );
  597.     ::SetPort( port );
  598.     ::SetGWorld( world, dev );
  599. }
  600.  
  601. void TBaseWindow::CalcMouseMove( const Point &where, RgnHandle moveRgn )
  602. {
  603.     if( !moveRgn )
  604.         return;
  605.     Point ul;
  606.     ul.h= 0; ul.v= 0;
  607.     GrafPtr oldPort;
  608.     ::GetPort( &oldPort );
  609.     ::SetPort( mWindow );
  610.     ::LocalToGlobal( &ul );
  611.     ::SetPort( oldPort );
  612.     if( !IsActive() ) {
  613.         RgnHandle above= ::NewRgn();
  614.         ::GetWindowStructureRgn( mWindow, moveRgn );
  615.         ClipAbove( above );
  616.         ::SectRgn( moveRgn, above, moveRgn );
  617.         ::DisposeRgn( above );
  618.         TMouseHandler::SGetMouse()->SetListener( this );
  619.         return;
  620.     }
  621.     RgnHandle thisRgn= ::NewRgn();
  622.     ::GetWindowStructureRgn( mWindow, thisRgn );
  623.     RgnHandle tempRgn= ::NewRgn();
  624.     ::GetWindowContentRgn( mWindow, tempRgn );
  625.     ::DiffRgn( thisRgn, tempRgn, thisRgn );
  626.     ClipAbove( tempRgn );
  627.     ::HNoPurge( (Handle)tempRgn );
  628.     ::SectRgn( tempRgn, thisRgn, thisRgn );
  629.     if( ::PtInRgn( where, thisRgn ) ) {
  630.         TMouseHandler::SGetMouse()->SetListener( this );
  631.         ::DisposeRgn( tempRgn );
  632.         ::CopyRgn( thisRgn, moveRgn );
  633.         ::DisposeRgn( thisRgn );
  634.         return;
  635.     }
  636.     ::GetWindowContentRgn( mWindow, moveRgn );
  637.     if( ::PtInRgn( where, moveRgn ) ) {
  638.         ::OffsetRgn( moveRgn, -ul.h, -ul.v );
  639.         if( mContent ) {
  640.             Point localPoint= where;
  641.             localPoint.h-= ul.h;
  642.             localPoint.v-= ul.v;
  643.             mContent->CalcMouseMove( localPoint, moveRgn );
  644.         }
  645.         ::OffsetRgn( moveRgn, ul.h, ul.v );
  646.         ::SectRgn( tempRgn, moveRgn, moveRgn );
  647.     } else {
  648.         ::DisposeRgn( moveRgn );
  649.         moveRgn= 0;
  650.     }
  651.     ::HPurge( (Handle)tempRgn );
  652.     ::DisposeRgn( tempRgn );
  653.     ::DisposeRgn( thisRgn );
  654. }
  655.  
  656. void TBaseWindow::HandleMouseMoved( TMouseEvent *, bool )
  657. {
  658. }